package com.huawei.hwid.update.c;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import com.huawei.hwid.activity.BridgeActivity;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.f.d;
import com.huawei.hwid.update.d.j;
import java.util.ArrayList;

public class a {
    public static void a(Context context, int i, j jVar) {
        e.b("UpdateManager", "startUpdate", true);
        if (context == null || jVar == null) {
            e.b("UpdateManager", "context or bean is null", true);
            return;
        }
        ArrayList arrayList = new ArrayList();
        com.huawei.hwid.f.d.a b = b(context);
        if (b == com.huawei.hwid.f.d.a.NOT_INSTALLED || b == com.huawei.hwid.f.d.a.DISABLED) {
            arrayList.add(Integer.valueOf(6));
        } else if (a(context)) {
            arrayList.add(Integer.valueOf(0));
            arrayList.add(Integer.valueOf(6));
        } else {
            arrayList.add(Integer.valueOf(5));
            arrayList.add(Integer.valueOf(6));
        }
        jVar.a(arrayList);
        Intent a = BridgeActivity.a(context, com.huawei.hwid.update.d.a.a(((Integer) arrayList.get(0)).intValue()));
        a.putExtra(com.huawei.hms.activity.BridgeActivity.EXTRA_DELEGATE_UPDATE_INFO, jVar);
        try {
            if (context instanceof Activity) {
                ((Activity) context).startActivityForResult(a, i);
                return;
            }
            a.setFlags(268435456);
            context.startActivity(a);
        } catch (RuntimeException e) {
            e.d("UpdateManager", "Silent can not start activity RuntimeException:", true);
        } catch (Exception e2) {
            e.d("UpdateManager", "Silent can not start activity:", true);
        }
    }

    private static boolean a(Context context) {
        return ((long) new d(context).b("com.huawei.appmarket")) >= 70203000;
    }

    private static com.huawei.hwid.f.d.a b(Context context) {
        return new d(context).a("com.huawei.appmarket");
    }
}
